package cn.tedu.hm.controller;

import cn.tedu.hm.pojo.AdminRole;
import cn.tedu.hm.pojo.vo.AdminRoleVO;
import cn.tedu.hm.service.AdminRoleService;
import cn.tedu.hm.wep.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/*
 *说明
 *
 *@author:TanXulLiang
 *@data:2023/2/17
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/userRole/")
@Api(tags="01. 用户角色模块")
@Transactional
public class UserRoleController {


    @Autowired(required = false)
    AdminRoleService adminService;


    @ApiOperation("新增用户角色")
    @ApiOperationSupport(order = 200)
    @PostMapping("addUserRole")
    public JsonResult<Void> addNew(AdminRole adminRole){
        adminService.save(adminRole);
        return  JsonResult.ok();
    }
    @ApiOperation("删除用户角色")
    @ApiOperationSupport(order = 300)
    @GetMapping("/delete/{id}")
    public JsonResult<Void> delete(@PathVariable Integer id){
        adminService.removeById(id);
        return  JsonResult.ok();
    }

    @ApiOperation("查询用户角色")
    @ApiOperationSupport(order = 300)
    @GetMapping("/select/{id}")
    public JsonResult<List<AdminRoleVO>> selectById(@PathVariable Integer id){
        List<AdminRoleVO> list=adminService.listByAdminId(id);
        return  JsonResult.ok(list);
    }

    @ApiOperation("修改用户角色")
    @ApiOperationSupport(order = 500)
    @PostMapping("/update/")
    public JsonResult<Void> update(AdminRole adminRole){
        log.debug("adminRole:{}",adminRole);
        adminService.updateById(adminRole);
        return  JsonResult.ok();
    }


}
